From 68202b8b7b88e8cf04e3045f17ddcf1a1e5b2a1e Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 21 Oct 2008 09:48:56 +0100 Subject: [PATCH] Update cpufreq statistic protection For struct pm_px, there are 3 pointer: pxpt, pt, trans_pt. Partly free pointer 'pt' and 'trans_pt' will result in little memory leak, and what is more, will result in protection issue when user access px statistic info through libxc. Signed-off-by: Liu, Jinsong --- xen/drivers/cpufreq/utility.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c index b9330c1de2..1c8176fabe 100644 --- a/xen/drivers/cpufreq/utility.c +++ b/xen/drivers/cpufreq/utility.c @@ -73,27 +73,30 @@ int cpufreq_statistic_init(unsigned int cpuid) struct pm_px *pxpt = cpufreq_statistic_data[cpuid]; const struct processor_pminfo *pmpt = processor_pminfo[cpuid]; - count = pmpt->perf.state_count; - if ( !pmpt ) return -EINVAL; + if ( pxpt ) + return 0; + + count = pmpt->perf.state_count; + + pxpt = xmalloc(struct pm_px); if ( !pxpt ) - { - pxpt = xmalloc(struct pm_px); - if ( !pxpt ) - return -ENOMEM; - memset(pxpt, 0, sizeof(*pxpt)); - cpufreq_statistic_data[cpuid] = pxpt; - } + return -ENOMEM; + memset(pxpt, 0, sizeof(*pxpt)); + cpufreq_statistic_data[cpuid] = pxpt; pxpt->u.trans_pt = xmalloc_array(uint64_t, count * count); - if (!pxpt->u.trans_pt) + if (!pxpt->u.trans_pt) { + xfree(pxpt); return -ENOMEM; + } pxpt->u.pt = xmalloc_array(struct pm_px_val, count); if (!pxpt->u.pt) { xfree(pxpt->u.trans_pt); + xfree(pxpt); return -ENOMEM; } @@ -120,7 +123,8 @@ void cpufreq_statistic_exit(unsigned int cpuid) return; xfree(pxpt->u.trans_pt); xfree(pxpt->u.pt); - memset(pxpt, 0, sizeof(struct pm_px)); + xfree(pxpt); + cpufreq_statistic_data[cpuid] = NULL; } void cpufreq_statistic_reset(unsigned int cpuid) -- 2.30.2